<template>
  <el-dialog :title="title" :visible.sync="open" width="600px">
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="授权OpenId" prop="openId">
        <el-input v-model="form.openId" placeholder="请输入授权OpenId" />
      </el-form-item>
      <el-form-item label="唯一CODE" prop="code" v-if="!code">
        <el-input v-model="form.code" placeholder="请输入唯一CODE" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {testTemplateMsg} from "@/api/cms/templatemsg";

  export default {
    name: 'testMsg',
    props:{
      code:{
        type:String
      }
    },
    data(){
      return {
        // 弹出层标题
        title: "测试消息",
        // 是否显示弹出层
        open: false,
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        },
      }
    },
    methods:{
      // 表单重置
      reset() {
        this.form = {
          code: undefined,
          openId: undefined
        };
        this.resetForm("form");
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      //打开窗口
      openTestWin(){
        this.open = true;
        this.form.code = this.code;
      },
      /** 提交按钮 */
      submitForm: function() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.form.code = this.code;
            if (this.form.code != undefined) {
              testTemplateMsg(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("发送成功");
                  this.open = false;
                  this.reset();
                } else {
                  this.msgError(response.msg);
                }
              });
            }
          }
        });
      },
    }
  }
</script>

<style scoped>

</style>
